using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
using System;

public class SkillClipData : ScriptableObject
{
    public float TotalTime { get; set; }
    public float StartTime;
    public float EndTime;

    [ShowInInspector]
    [DelayedProperty]
    [PropertyOrder(-1)]
    public string Name
    {
        get {return name;}
        set {name = value;}
    }

    public ExecuteClipType ExecuteClipType;

    [Space(10)]
    [ShowIf("ExecuteClipType", ExecuteClipType.ActionEvent)]
    public ActionEventData ActionEventData;

    [Space(10)]
    [ShowIf("ExecuteClipType", ExecuteClipType.CollisionExecute)]
    public CollisionExecuteData CollisionExecuteData;

    [Space(10)]
    [ShowIf("ExecuteClipType", ExecuteClipType.Animation)]
    public AnimationData AnimationData;

    [Space(10)]
    [ShowIf("ExecuteClipType", ExecuteClipType.Audio)]
    public AudioData AudioData;

    [Space(10)]
    [ShowIf("ExecuteClipType", ExecuteClipType.ParticleEffect)]
    public ParticleEffectData ParticleEffectData;

    public float Duration { get=> (EndTime - StartTime); }

    public SkillClipData GetClipTime()
    {
        return this;
    }

}

public enum ExecuteClipType
{
    CollisionExecute = 0,
    ActionEvent = 1,
    Animation = 2,
    Audio = 3,
    ParticleEffect = 4,
}

[LabelText("执行体目标传入类型")]
public enum ExecuteTargetInputType
{
    [LabelText("None")]
    None = 0,
    [LabelText("传入目标实体")]
    Target = 1,
    [LabelText("传入目标点")]
    Point = 2,
}

[LabelText("事件类型")]
public enum FireEventType
{
    [LabelText("出发赋给效果")]
    AssignEffect = 0,
    [LabelText("触发新执行体")]
    TriggerNewExecute = 1,
}
[Serializable]
public class ActionEventData
{
    public FireEventType FireEventType;
    [ShowIf("FireEventType", FireEventType.AssignEffect)]
    public EffectApplyType EffectApply;
    [ShowIf("FireEventType", FireEventType.TriggerNewExecute)]
    public string ExecuteClipName;
}

[LabelText("碰撞执行类型")]
public enum CollisionExecuteType
{
    [LabelText("脱手执行")]
    OutOfHand = 0,
    [LabelText("执手执行")]
    InHand = 1,
}

[Serializable]
public class CollisionExecuteData
{
    public CollisionExecuteType ExecuteType;
    public ActionEventData ActionData;

    [Space(10)]
    public CollisionShape Shape;
    [ShowIf("Shape", CollisionShape.Sphere), LabelText("半径")]
    public float Radius;
    [ShowIf("Shape", CollisionShape.Box)]
    public Vector3 Center;
    [ShowIf("Shape", CollisionShape.Box)]
    public Vector3 Size;

    [Space(10)]
    public CollisionMoveType MoveType;
    [DelayedProperty]
    public GameObject ObjAsset;

    [ShowIf("ShowSpeed")]
    public float Speed;
    public bool ShowSpeed { get => MoveType != CollisionMoveType.SelectedPosition && MoveType != CollisionMoveType.SelectedDirection; }
    public bool ShowPoints { get => MoveType == CollisionMoveType.PathFly || MoveType == CollisionMoveType.SelectedDirectionPathFly; }
    [ShowIf("ShowPoints")]
    public List<CtrlPoint> Points;

    public List<CtrlPoint> GetCtrlPoints()
    {
        var list = new List<CtrlPoint>();
        foreach(var point in Points)
        {
            var newPoint = new CtrlPoint();
            newPoint.Pos = point.Pos;
            newPoint.Type = point.Type;
            newPoint.InTangent = point.InTangent;
            newPoint.OutTangent = point.OutTangent;
            list.Add(newPoint);
        }
        return list;
    }

}

[Serializable]
public class ParticleEffectData
{
    public GameObject ParticleAsset;
}

[Serializable]
public class AnimationData
{
    public AnimationClip AnimationAsset;
}

[Serializable]
public class AudioData
{
    public AudioClip AudioAsset;
}

////////////////////////execute event emitter////////////////////////
[LabelText("碰撞体形状")]
public enum CollisionShape
{
    [LabelText("圆形")]
    Sphere,
    [LabelText("举行")]
    Box,
    [LabelText("扇形")]
    Sector,
    [LabelText("自定义")]
    Custom,
}

[LabelText("碰撞体移动类型")]
public enum CollisionMoveType
{
    [LabelText("可选位置碰撞体")]
    SelectedPosition,
    [LabelText("可选朝向碰撞体")]
    SelectedDirection,
    [LabelText("目标飞行碰撞体")]
    TargetFly,
    [LabelText("朝向飞行碰撞体")]
    ForwardFly,
    [LabelText("路径飞行碰撞体")]
    PathFly,
    [LabelText("可选朝向路径飞行")]
    SelectedDirectionPathFly,
}

[LabelText("应用效果")]
public enum EffectApplyType
{
    [LabelText("赋给目标")]
    AllEffects,

    [LabelText("其他")]
    Other,
}
